home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / DroidA.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  14.7 KB  |  495 lines

  1. class classes.enemy.DroidA
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var matrixCoords;
  7.    var id;
  8.    var form;
  9.    var clip;
  10.    var advanceMax;
  11.    var advanceMax2;
  12.    var matrixVar;
  13.    var dir;
  14.    var f2;
  15.    var axis;
  16.    var xDest;
  17.    var yDest;
  18.    var oldDir;
  19.    var xMov = 0;
  20.    var yMov = 0;
  21.    var xmt = 0;
  22.    var ymt = 0;
  23.    var xMovT = 0;
  24.    var yMovT = 0;
  25.    var speedOrig = 8;
  26.    var speed = 8;
  27.    var xDestMet = false;
  28.    var yDestMet = false;
  29.    var c = 0;
  30.    var feelerInfo = [[-400,0,400,40],[0,0,400,40],[0,-400,40,400],[0,0,40,400]];
  31.    var dirArray = ["L","R","U","D"];
  32.    var power = 15;
  33.    var Name = "droidA";
  34.    function DroidA(px, py, pmoveScript, pmatrixCoords, pform, pid)
  35.    {
  36.       this.x = px;
  37.       this.y = py;
  38.       this.moveScript = pmoveScript.slice();
  39.       this.matrixCoords = pmatrixCoords.slice();
  40.       this.id = pid;
  41.       this.form = pform.slice();
  42.       _root.d = _root.d + 1;
  43.       this.clip = _root.attachMovie("droidA","droidA" + this.id + "Clip",_root.d + 50000);
  44.       this.clip._x = this.x;
  45.       this.clip._y = this.y;
  46.       this.speed *= _root.dif.speed;
  47.       this.speedOrig = this.speed;
  48.       this.advanceMax = 60 / (this.speed / 2);
  49.       this.advanceMax2 = 50 / (this.speed / 2);
  50.       if(this.matrixCoords[0] == "free")
  51.       {
  52.          this.matrixVar = 0;
  53.       }
  54.       else
  55.       {
  56.          this.matrixVar = 1;
  57.       }
  58.       this.speedVar();
  59.       var _loc3_ = _root.randRange(-20,20);
  60.       var _loc4_ = new flash.geom.Transform(this.clip);
  61.       var _loc5_ = new flash.geom.ColorTransform(1,1,1,1,_loc3_,_loc3_,_loc3_,0);
  62.       _loc4_.colorTransform = _loc5_;
  63.       this.parseMoveScript();
  64.       _root.stats.created = _root.stats.created + 1;
  65.    }
  66.    function broBehind()
  67.    {
  68.       this.matrixVar = 0;
  69.       this.yMovT = 0;
  70.       if(random(3) == 1)
  71.       {
  72.          var _loc3_ = _root.randRange2(1.2,1.4);
  73.          this.xMovT = this.dir != "L" ? _loc3_ * this.speed : -1 * _loc3_ * this.speed;
  74.          this.getDirString();
  75.          this.clip.body.gotoAndPlay("attack");
  76.          this.clip.body.face.gotoAndPlay("attack");
  77.          this.clip.body.flame.gotoAndPlay("start");
  78.          this.f2 = "attacking";
  79.       }
  80.       else
  81.       {
  82.          this[this.axis + "MovT"] = 0;
  83.          this.axis = random(2) <= 0 ? "x" : "y";
  84.          _loc3_ = _root.randRange2(0.9,1.1);
  85.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * _loc3_ * this.speed : _loc3_ * this.speed;
  86.          this.getDirString();
  87.          this.clip.body.flame.gotoAndPlay("start");
  88.          this.f2 = "wander";
  89.       }
  90.    }
  91.    function speedVar()
  92.    {
  93.       if(random(3) == 1)
  94.       {
  95.          this.speed *= _root.randRange2(0.9999,1.0001);
  96.       }
  97.    }
  98.    function bombed(num)
  99.    {
  100.       this.f2 = "death";
  101.    }
  102.    function parseMoveScript()
  103.    {
  104.       this.dir = this.moveScript[0];
  105.       if(this.dir == "break")
  106.       {
  107.          delete this.moveScript;
  108.          this[this.axis + "MovT"] = 0;
  109.          if(this.matrixCoords[0] == "free")
  110.          {
  111.             this.f2 = "wander";
  112.             this.axis = random(10) <= 4 ? "y" : "x";
  113.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  114.             this.speedVar();
  115.             this.getDirString();
  116.          }
  117.          else
  118.          {
  119.             this.xDest = _root.advanceDir != "L" ? this.matrixCoords[0] * 60 : this.matrixCoords[0] * 60 + 320;
  120.             this.yDest = this.matrixCoords[1] * 50 + 10;
  121.             this.axis = Math.abs(this.xDest - this.x) <= Math.abs(this.yDest - this.y) ? "y" : "x";
  122.             this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  123.             this.getDirString();
  124.             this.speedVar();
  125.             this.f2 = "gotoMatrix";
  126.          }
  127.       }
  128.       else
  129.       {
  130.          this[this.axis + "MovT"] = 0;
  131.          this.f2 = "gotoXYDest";
  132.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  133.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  134.          this.speedVar();
  135.          if(this.dir == "L" || this.dir == "U")
  136.          {
  137.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  138.          }
  139.          else
  140.          {
  141.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  142.          }
  143.          this.moveScript.splice(0,2);
  144.       }
  145.    }
  146.    function gotoXYDest()
  147.    {
  148.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  149.       {
  150.          if(this.axis == "x")
  151.          {
  152.             this.x = this.xDest;
  153.          }
  154.          else
  155.          {
  156.             this.y = this.yDest;
  157.          }
  158.          this.parseMoveScript();
  159.       }
  160.    }
  161.    function gotoMatrix()
  162.    {
  163.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  164.       {
  165.          if(this.axis == "x")
  166.          {
  167.             this.x = this.xDest;
  168.          }
  169.          else
  170.          {
  171.             this.y = this.yDest;
  172.          }
  173.          this[this.axis + "MovT"] = 0;
  174.          this.axis = this.axis != "x" ? "x" : "y";
  175.          this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  176.          this.getDirString();
  177.          this.speed = this.speedOrig;
  178.       }
  179.       if(Math.abs(this.x - this.xDest) < this.speed + 1 && Math.abs(this.y - this.yDest) < this.speed + 1)
  180.       {
  181.          this.x = this.clip._x = this.xDest;
  182.          this.y = this.clip._y = this.yDest;
  183.          this.xMovT = this.xMov = 0;
  184.          this.yMovT = this.yMov = 0;
  185.          this.matrixVar = 2;
  186.          this.dir = _root.advanceDir;
  187.          this.clip.body.flame.gotoAndPlay("still");
  188.          _root.matrixNum = _root.matrixNum + 1;
  189.          if(_root.matrixNum >= _root.matrixSize)
  190.          {
  191.             _root.matrixComplete = true;
  192.          }
  193.          _root["formB" + this.form[0]] = "matrixed";
  194.          this.f2 = "wait";
  195.       }
  196.    }
  197.    function getDirString()
  198.    {
  199.       if(this.xMovT < -1)
  200.       {
  201.          this.dir = "L";
  202.       }
  203.       else if(this.xMovT > 1)
  204.       {
  205.          this.dir = "R";
  206.       }
  207.       else if(this.yMovT > 1)
  208.       {
  209.          this.dir = "D";
  210.       }
  211.       else if(this.yMovT < -1)
  212.       {
  213.          this.dir = "U";
  214.       }
  215.    }
  216.    function wait()
  217.    {
  218.       if(random(1000) >= 998 + _root.dif.wait && _root.matrixComplete)
  219.       {
  220.          this.dir = this.findDir();
  221.          if(this.dir == _root.advanceDir)
  222.          {
  223.             this.xMovT = _root.advanceDir != "L" ? 1.3 * this.speed : -1.3 * this.speed;
  224.             this.getDirString();
  225.             this.clip.body.gotoAndPlay("attack");
  226.             this.clip.body.face.gotoAndPlay("attack");
  227.             this.clip.body.flame.gotoAndPlay("start");
  228.             this.f2 = "attacking";
  229.             this.matrixVar = 0;
  230.          }
  231.          else if(this.dir == "U" || this.dir == "D")
  232.          {
  233.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  234.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  235.             this.matrixVar = 0;
  236.             this.c = 0;
  237.             this.f2 = "leavingMatrix";
  238.             this.clip.body.flame.gotoAndPlay("start");
  239.          }
  240.          else
  241.          {
  242.             this.dir = _root.advanceDir;
  243.          }
  244.       }
  245.    }
  246.    function leavingMatrix()
  247.    {
  248.       this.c = this.c + 1;
  249.       if(this.c > this.advanceMax2)
  250.       {
  251.          this.c = 0;
  252.          this.dir = this.findDir();
  253.          if(this.dir == _root.advanceDir)
  254.          {
  255.             this.yMovT = 0;
  256.             this.xMovT = _root.advanceDir != "L" ? 1.3 * this.speed : -1.3 * this.speed;
  257.             this.getDirString();
  258.             this.clip.body.gotoAndPlay("attack");
  259.             this.clip.body.face.gotoAndPlay("attack");
  260.             this.f2 = "attacking";
  261.          }
  262.       }
  263.    }
  264.    function findDir()
  265.    {
  266.       _root.d = _root.d + 1;
  267.       _root.attachMovie("feeler","feelerClip",_root.d);
  268.       var _loc7_ = [];
  269.       var _loc9_ = 0;
  270.       var _loc11_ = this.dirArray.length;
  271.       while(_loc9_ < _loc11_)
  272.       {
  273.          _root.feelerClip._x = this.x + this.feelerInfo[_loc9_][0];
  274.          _root.feelerClip._y = this.y + this.feelerInfo[_loc9_][1];
  275.          _root.feelerClip._width = this.feelerInfo[_loc9_][2];
  276.          _root.feelerClip._height = this.feelerInfo[_loc9_][3];
  277.          var _loc3_ = 0;
  278.          var _loc8_ = _root.chars.length;
  279.          var _loc6_ = false;
  280.          while(_loc3_ < _loc8_)
  281.          {
  282.             var _loc5_ = _root.chars[_loc3_] + "Clip";
  283.             if(_root.feelerClip.hitTest(_root[_loc5_]))
  284.             {
  285.                var _loc4_ = _root.chars[_loc3_];
  286.                if(_root[_loc4_].matrixVar == 2 && _loc4_ != this.Name + this.id)
  287.                {
  288.                   _loc6_ = true;
  289.                   break;
  290.                }
  291.             }
  292.             _loc3_ = _loc3_ + 1;
  293.          }
  294.          if(!_loc6_)
  295.          {
  296.             var _loc10_ = _root.advanceDir != "L" ? "L" : "R";
  297.             if(this.dirArray[_loc9_] != _loc10_)
  298.             {
  299.                _loc7_.push(this.dirArray[_loc9_]);
  300.             }
  301.          }
  302.          _loc9_ = _loc9_ + 1;
  303.       }
  304.       _loc9_ = 0;
  305.       _loc11_ = _loc7_.length;
  306.       if(_loc9_ < _loc11_)
  307.       {
  308.          if(_loc7_[_loc9_] == _root.advanceDir)
  309.          {
  310.             return _root.advanceDir;
  311.          }
  312.          return _loc7_[random(_loc7_.length)];
  313.       }
  314.    }
  315.    function attacking()
  316.    {
  317.    }
  318.    function death()
  319.    {
  320.       _root.stats.destroyed = _root.stats.destroyed + 1;
  321.       _root.stats.score += 100;
  322.       if(this.matrixVar == 1)
  323.       {
  324.          _root.matrixNum = _root.matrixNum + 1;
  325.          if(_root.matrixNum >= _root.matrixSize)
  326.          {
  327.             _root.matrixComplete = true;
  328.          }
  329.       }
  330.       _root.powerUp(this.x,this.y,96);
  331.       var _loc3_ = 0;
  332.       var _loc4_ = _root["form" + this.form[0]].length;
  333.       while(_loc3_ < _loc4_)
  334.       {
  335.          if(_root["form" + this.form[0]][_loc3_] == "droidA" + this.id)
  336.          {
  337.             _root["form" + this.form[0]].splice(_loc3_,1);
  338.             if(_root["form" + this.form[0]].length == 0)
  339.             {
  340.                delete _root["form" + this.form[0]];
  341.                if(_root["formB" + this.form[0]] == "matrixed")
  342.                {
  343.                   _root.createPowerUp([this.x,this.y,"coin1"]);
  344.                   _root.stats.score += 100;
  345.                }
  346.                else
  347.                {
  348.                   _root.createPowerUp([this.x,this.y,"coin1"]);
  349.                   _root.stats.score += 200;
  350.                }
  351.                delete _root["formB" + this.form[0]];
  352.             }
  353.             break;
  354.          }
  355.          _loc3_ = _loc3_ + 1;
  356.       }
  357.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(80,130),_root.randRange(75,100),"Red"]);
  358.       _loc3_ = 0;
  359.       _loc4_ = random(3);
  360.       while(_loc3_ < _loc4_)
  361.       {
  362.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"droidA"]);
  363.          _loc3_ = _loc3_ + 1;
  364.       }
  365.       _root.createEnemySoul([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"red"]);
  366.       _root.audio.playLevel4("droidX" + (random(3) + 1),_root.randRange(16,35));
  367.       _root.removeChar("droidA" + this.id);
  368.       this.f2 = "";
  369.    }
  370.    function advance()
  371.    {
  372.       this.dir = _root.advanceDir;
  373.       this.clip.body.flame.gotoAndPlay("advance");
  374.       this.xMovT = _root.advanceDir != "L" ? 1 * (this.speed / 2) : -1 * (this.speed / 2);
  375.       this.f2 = "advancing";
  376.    }
  377.    function advancing()
  378.    {
  379.       this.c = this.c + 1;
  380.       if(this.c > this.advanceMax)
  381.       {
  382.          this.xMovT = 0;
  383.          this.c = 0;
  384.          this.f2 = "wait";
  385.          _root.d = _root.d + 1;
  386.          _root.attachMovie("sight","sightClip",_root.d);
  387.          _root.sightClip.gotoAndStop("hindSight");
  388.          _root.sightClip._x = this.x;
  389.          _root.sightClip._y = this.y;
  390.          if(_root.advanceDir == "L")
  391.          {
  392.             _root.sightClip._rotation = 180;
  393.          }
  394.          if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  395.          {
  396.             _root.broBehind();
  397.          }
  398.          removeMovieClip(_root.sightClip);
  399.       }
  400.    }
  401.    function wander()
  402.    {
  403.       if(random(100) > 98 + _root.dif.wander)
  404.       {
  405.          this[this.axis + "MovT"] = 0;
  406.          this.axis = this.axis != "x" ? "x" : "y";
  407.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  408.          this.getDirString();
  409.       }
  410.    }
  411.    function death2()
  412.    {
  413.       _root.removeChar("droidA" + this.id);
  414.       this.f2 = "";
  415.    }
  416.    function main()
  417.    {
  418.       this[this.f2]();
  419.       if(this.oldDir != this.dir)
  420.       {
  421.          this.clip.gotoAndStop("fly" + this.dir);
  422.       }
  423.       this.oldDir = this.dir;
  424.       var _loc4_ = 0;
  425.       var _loc6_ = _root.broShots.length;
  426.       while(_loc4_ < _loc6_)
  427.       {
  428.          var _loc5_ = _root.broShots[_loc4_] + "Clip";
  429.          if(this.clip.hitTest(_root[_loc5_]))
  430.          {
  431.             this.f2 = "death";
  432.             _root[_root.char].fc = _root[_root.char].fireFreq - _root.rapidVar;
  433.             var _loc3_ = _root.broShots[_loc4_];
  434.             _root[_loc3_].exploX = this.x + this.clip._width / 2;
  435.             _root[_loc3_].exploY = this.y + this.clip._height / 2;
  436.             _root[_loc3_].hit(1);
  437.             break;
  438.          }
  439.          _loc4_ = _loc4_ + 1;
  440.       }
  441.       if(this.clip.hitTest(_root[_root.char + "Clip"]))
  442.       {
  443.          _root[_root.char].hit(this.xMov,this.yMov,100,this.power);
  444.          this.f2 = "death";
  445.       }
  446.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  447.       {
  448.          delete _root["form" + this.form[0]];
  449.          delete _root["formB" + this.form[0]];
  450.          this.f2 = "death2";
  451.       }
  452.       if(this.xMovT < this.xMov)
  453.       {
  454.          this.xMov -= 1;
  455.       }
  456.       else if(this.xMovT > this.xMov)
  457.       {
  458.          this.xMov += 1;
  459.       }
  460.       else
  461.       {
  462.          this.xMov = this.xMovT;
  463.       }
  464.       if(this.yMovT < this.yMov)
  465.       {
  466.          this.yMov -= 1;
  467.       }
  468.       else if(this.yMovT > this.yMov)
  469.       {
  470.          this.yMov += 1;
  471.       }
  472.       else
  473.       {
  474.          this.yMov = this.yMovT;
  475.       }
  476.       this.xmt = this.xMov;
  477.       this.ymt = this.yMov;
  478.       if(random(10) == 1)
  479.       {
  480.          if(this.axis == "y")
  481.          {
  482.             this.xmt += _root.randRange2(-1,1);
  483.          }
  484.          else
  485.          {
  486.             this.ymt += _root.randRange2(-1,1);
  487.          }
  488.       }
  489.       this.x += this.xmt;
  490.       this.y += this.ymt;
  491.       this.clip._x = this.x;
  492.       this.clip._y = this.y;
  493.    }
  494. }
  495.